#include "widget.h"
#include "ui_widget.h"

#include <QMenu>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    //窗口名字
    this->setWindowTitle("智能家居控制平台");

    //开关窗口背景


    //设置托盘
    setWindowIcon(QIcon(":/picture/traycon.png"));
    trayIcon = new QSystemTrayIcon(QIcon(":/picture/traycon.png"), this);

    //设置系统托盘图标
    trayIcon->setToolTip("智能家居控制平台");
    QMenu * menu = new QMenu;
    menu->addAction(tr("退出"), qApp, SLOT(quit()));
    trayIcon->setContextMenu(menu);

    //电灯图标
    lightPix.load(":/picture/light.png");
    ui->lightPictureLabel->setPixmap(lightPix);
    ui->lightPictureLabel->setScaledContents(true);

    //空调图标
    airconditionPix.load(":/picture/airconditioner.png");
    ui->airconditionPicyureLabel->setPixmap(airconditionPix);
    ui->airconditionPicyureLabel->setScaledContents(true);

    //摄像头图标
    cameraPix.load(":/picture/camera.png");
    ui->cameraPictureLabel->setPixmap(cameraPix);
    ui->cameraPictureLabel->setScaledContents(true);

    //温度符号图标
    temperatureSymbol.load(":/picture/temperatureSymbol.png");
    ui->temperationSymbolLabel->setPixmap(temperatureSymbol);
    ui->temperationSymbolLabel->setScaledContents(true);


    //湿度符号图标
    humiditySymbol.load(":/picture/humiditySymbol.png");
    ui->humiditySymbolLabel->setPixmap(humiditySymbol);
    ui->humiditySymbolLabel->setScaledContents(true);

    //设置电灯打开图标
    lightONPix.load(":/picture/lightON.png");

    //设置电灯关闭图标
    lightOFFPix.load(":/picture/lightOFF.png");
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_livingLightONOFFBtn_clicked()
{
    if(ui->livingLightONOFFBtn->text() == "客厅灯  ON")
    {
        //显示电灯打开的图标
        ui->livingLightONOFFPictureLabel->setPixmap(lightONPix);
        ui->livingLightONOFFPictureLabel->setScaledContents(true);

        //改变电灯开关上的文本
        ui->livingLightONOFFBtn->setText("客厅灯  OFF");
    }
    else if(ui->livingLightONOFFBtn->text() == "客厅灯  OFF")
    {
        //显示电灯关闭图标
        ui->livingLightONOFFPictureLabel->setPixmap(lightOFFPix);
        ui->livingLightONOFFPictureLabel->setScaledContents(true);

        //改变电灯开关上的文本
        ui->livingLightONOFFBtn->setText("客厅灯  ON");
    }
}

void Widget::on_bedroomLightONOFFBtn_clicked()
{
    if(ui->bedroomLightONOFFBtn->text() == "卧室灯  ON")
    {
        //显示电灯打开的图标
        ui->bedroomLightONOFFPictureLabel->setPixmap(lightONPix);
        ui->bedroomLightONOFFPictureLabel->setScaledContents(true);

        //改变电灯开关上的文本
        ui->bedroomLightONOFFBtn->setText("卧室灯  OFF");
    }
    else if(ui->bedroomLightONOFFBtn->text() == "卧室灯  OFF")
    {
        //显示电灯关闭图标
        ui->bedroomLightONOFFPictureLabel->setPixmap(lightOFFPix);
        ui->bedroomLightONOFFPictureLabel->setScaledContents(true);

        //改变电灯开关上的文本
        ui->bedroomLightONOFFBtn->setText("卧室灯  ON");
    }
}
